home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 398 / 398.xpi / chrome / forecastfox.jar / content / profiles / profiles.js < prev    next >
Text File  |  2010-02-04  |  4KB  |  131 lines

  1. /*------------------------------------------------------------------------------
  2.   Copyright (c) 2008 Ensolis, LLC. All Rights Reserved.
  3.   ----------------------------------------------------------------------------*/
  4.  
  5. var gProfiles = null;
  6.  
  7. function profilesLoad()
  8. {
  9.   gProfiles = new ProfilesModule();
  10.   gProfiles.start();
  11. }
  12.  
  13. function profilesUnload()
  14. {
  15.   gProfiles.stop();
  16.   gProfiles = null;
  17. }
  18.  
  19. function ProfilesModule() {}
  20. ProfilesModule.prototype = {
  21.   _prfSvc: null,
  22.   _type: null,
  23.   _bundle: null,
  24.   _name: null,
  25.   _id: null,
  26.   _prompt: null,
  27.   
  28.   start: function ProfilesModule_start()
  29.   {
  30.     var mgrSvc = Cc["@ensolis.com/forecastfox/manager-service;1"].getService(Ci.ffIManagerService);
  31.     this._prfSvc = mgrSvc.profiles;
  32.     this._type = window.arguments[0];
  33.     this._bundle = document.getElementById("ff-bundle-profiles");  
  34.     this._name = document.getElementById("ff-text-name");
  35.     this._id = document.getElementById("ff-text-id");
  36.          
  37.     //set description
  38.     document.getElementById("ff-profiles-header").title = this._bundle.getString("ff.profiles." + this._type);
  39.     var item = this._prfSvc.current;
  40.     switch (this._type) {
  41.       case "create":
  42.         this._id.value = this._prfSvc.createID();
  43.         this._name.value = "";
  44.         break;
  45.       case "rename":
  46.         this._id.value = item.ID;
  47.         this._name.value = item.name;
  48.         break;
  49.       case "remove":
  50.         this._name.readonly = true;
  51.         this._id.value = item.ID;
  52.         this._name.value = item.name;
  53.         break;   
  54.     }
  55.     
  56.     //set focus
  57.     if (this._type != "remove") {
  58.       this._name.focus();
  59.       this._name.select();
  60.     }
  61.   },
  62.   
  63.   stop: function ProfilesModule_stop()
  64.   {
  65.     this._dskSvc = null;  
  66.     this._prfSvc = null;
  67.     this._type = null;
  68.     this._bundle = null;
  69.     this._id = null;
  70.     this._name = null;
  71.     this._prompt = null; 
  72.   },
  73.  
  74.   accept: function ProfilesModule_accept()
  75.   {
  76.     //get the current list of items
  77.     var items = this._prfSvc.getItems({});
  78.     var item = this._prfSvc.current;
  79.           
  80.       switch (this._type) {
  81.         case "create":
  82.           //check that the name is valid
  83.           if (this._name.value == "") {
  84.             this._alert("ff.profiles.invalid");
  85.             return;
  86.           }
  87.           
  88.           //add a new profile
  89.           var newItem = this._createItem();
  90.           this._prfSvc.setItem(newItem);
  91.           this._prfSvc.current = newItem;
  92.           break;
  93.         case "rename":
  94.           //check that the name is valid
  95.           if (this._name.value == "") {
  96.             this._alert("ff.profiles.invalid");
  97.             return;
  98.           }
  99.           
  100.           //rename the item
  101.           item.setProperty("name", this._name.value);
  102.           this._prfSvc.setItem(item);        
  103.           break;         
  104.         case "remove":
  105.           //check that we aren't the last profile
  106.           if (items.length == 1) {
  107.             this._alert("ff.profiles.last");
  108.             return; 
  109.           }
  110.           this._prfSvc.deleteItem(item.ID);
  111.           break;         
  112.       }
  113.      
  114.       window.close();
  115.   },
  116.   
  117.   _alert: function ProfilesModule__alert(aText)
  118.   {
  119.     if (!this._prompt)
  120.       this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  121.     this._prompt.alert(window, this._bundle.getString("ff.profiles"), this._bundle.getString(aText));
  122.   },
  123.   
  124.   _createItem: function ProfilesModule__createItem()
  125.   {
  126.     var item = this._prfSvc.current.clone();
  127.     item.setProperty("ID", this._id.value);
  128.     item.setProperty("name", this._name.value);
  129.     return item;
  130.   }
  131. };